﻿<UserControl x:Class="cmdr.Editor.Views.MappingListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:views="clr-namespace:cmdr.Editor.Views"        
             xmlns:behaviors="clr-namespace:cmdr.Editor.Behaviors"
             xmlns:behaviorsWpfControls="clr-namespace:cmdr.WpfControls.Behaviors;assembly=cmdr.WpfControls"
             xmlns:controls="clr-namespace:cmdr.Editor.Views.Controls"
             xmlns:ddButton="clr-namespace:cmdr.WpfControls.DropDownButton;assembly=cmdr.WpfControls"
             xmlns:cdg="clr-namespace:cmdr.WpfControls.CustomDataGrid;assembly=cmdr.WpfControls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="20"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <!-- Make sure ItemsSource is bound later than SynchronizedSelectedItems, because changing the ItemsSource will reset any selection! -->
        <cdg:CustomDataGrid Grid.Row="0" x:Name="MappingsGrid"
                            AutoGenerateColumns="False"
                            ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                            behaviorsWpfControls:MultiSelectorBehavior.SynchronizedSelectedItems="{Binding SelectedMappings}"
                            ItemsSource="{Binding Mappings, Mode=OneWay}"
                            behaviorsWpfControls:DraggableRowsBehavior.DropAction="{Binding DropCommand, Mode=OneTime}"
                            >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding SelectionChangedCommand, Mode=OneTime}" 
                                           CommandParameter="{Binding ElementName=MappingsGrid, Path=SelectedItems}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <DataGrid.Columns>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.Id, Mode=OneTime}" Header="Id" Width="75" IsReadOnly="True"/>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.Type, Mode=OneTime}" Header="I/O" IsReadOnly="True"/>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.TraktorCommand, Mode=OneWay}" Header="Command" Width="200" IsReadOnly="True"/>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.AssignmentExpression, Mode=OneWay}" Header="Assignment" Width="100" IsReadOnly="True"/>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.ConditionExpression, Mode=OneWay}" Header="Condition" Width="150" IsReadOnly="True"/>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.Interaction, Mode=OneWay}" Header="Interaction" Width="100" IsReadOnly="True"/>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.MappedTo, Mode=OneWay}" Header="Mapped To" Width="100" IsReadOnly="True"/>
                <cdg:CustomDataGridTextColumn Binding="{Binding Item.Comment, UpdateSourceTrigger=PropertyChanged}" Header="Comment" MinWidth="75" Width="*"/>
            </DataGrid.Columns>
            <DataGrid.InputBindings>
                <KeyBinding Key="C" Modifiers="Ctrl" Command="ApplicationCommands.NotACommand"/>
                <KeyBinding Key="L" Modifiers="Ctrl" Command="ApplicationCommands.NotACommand"/>
                <KeyBinding Key="Delete" Command="ApplicationCommands.NotACommand"/>
            </DataGrid.InputBindings>
        </cdg:CustomDataGrid>


        <DockPanel Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" LastChildFill="True">
            <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right" FontSize="11">
                <Run Text="{Binding Path=SelectedItems.Count, ElementName=MappingsGrid, Mode=OneWay}" />
                <Run Text=" / " />
                <Run Text="{Binding Path=Items.Count, ElementName=MappingsGrid, Mode=OneWay}" />
                <Run Text=" selected" />
            </TextBlock>
        </DockPanel>

        <DockPanel Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Center" LastChildFill="True">
            <StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
                <ddButton:DropDownButton Content="Add In" MenuPlacement="Top"
                                         ItemsSource="{Binding InCommands}"
                                         Command="{Binding AddMappingCommand}"
                                         Width="75" Margin="0,0,5,0"/>
                <ddButton:DropDownButton Content="Add Out" MenuPlacement="Top"
                                         ItemsSource="{Binding OutCommands}"
                                         Command="{Binding AddMappingCommand}"
                                         Width="75"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Right">
                <controls:SearchControl Width="100" DataContext="{Binding SearchViewModel, Mode=OneWay}" />
            </StackPanel>
        </DockPanel>

    </Grid>
</UserControl>
